package cn.fl.demo.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.demo.dto.DemoDTO;
import cn.fl.demo.service.IDemoService;
import cn.fl.demo.transform.DemoVOTransform;
import cn.fl.demo.vo.DemoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.transform.SysCdMapDVOTransform;
import cn.fl.system.vo.SysCdMapDVO;

@Service
public class DemoServiceImpl implements IDemoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);
	
	/**
	 * Demo API 服务
	 */
	/*@Autowired
	private IDemoApiService demoApiService;*/
	
	/**
	 * 系统服务
	 */
	@Autowired
	private ISysCdMapApiService sysCdMapApiService;

	@Override
	public DemoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		DemoDTO dto = null;//this.demoApiService.selectById(id);
		return DemoVOTransform.toVO(dto);
	}

	@Override
	public Long add(DemoVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		//系统日志-有用户的情况下
		BaseLogUtils.info(logger, "add", "新增Demo数据.", CurrentThreadContext.getCurrentUserName());
		
		//系统日志-无用户的情况下
		BaseLogUtils.info(logger, "add", "新增Demo数据.");
		return null;//this.demoApiService.add(DemoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		return false;//this.demoApiService.removeById(id);
	}

	@Override
	public boolean modify(DemoVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		return false;//this.demoApiService.modify(DemoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		return page;//this.demoApiService.searchListPage(page);
	}

	@Override
	public List<SysCdMapDVO> searchSysCdMapDWithTargetAtomList(SysCdMapDQueryCondition condition) throws BaseException {
		if(null == condition 
				|| StringUtils.isEmpty(condition.getmTypCd())
				|| StringUtils.isEmpty(condition.getSysCd())
				/*|| StringUtils.isEmpty(condition.getsGrpCd())*/
				|| StringUtils.isEmpty(condition.getsCode())){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		List<SysCdMapDDTO> list = this.sysCdMapApiService.searchSysCdMapDWithTargetList(condition);
		return SysCdMapDVOTransform.toVOList(list);
	}
}
